public with sharing class SendPageAsPDFController {
	
	public String inputA{get;set;}
	public String inputB{get;set;}
	public boolean flag{get;set;}
	public String toAddress{get;set;}
	public String body{get;set;}
	public String attachmentName {get;set;}
	
	private Blob pdfContent {get;set;}
	
	
	
	public SendPageAsPDFController(){
		flag = false;
		
	}
	
	/*public PageReference saveAsPDF(){
		PageReference pdf = Page.PDFGenerator;
		pdf.getParameters().put('inputA',inputA);
		pdf.getParameters().put('inputB',inputB);
		
		pdf.setRedirect(true);
		return pdf;
		
		flag = true;
		
		PageReference pref = ApexPages.currentPage();
		pref.setRedirect(true);
		
		return pref;
		
	}*/
	
	public void saveAsPDF(){
		
		PageReference pdf = Page.PDFGenerator;
		pdf.getParameters().put('inputA',inputA);
		pdf.getParameters().put('inputB',inputB);
		pdfContent = pdf.getContent();
		
		flag = true;
	}
	
	public PageReference sendMail(){
		
		
		
		Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
    	attach.setContentType('application/pdf');
    	attach.setFileName(attachmentName);
    	attach.setInline(false);
    	attach.Body = pdfContent;
    	
    	
    	Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    	mail.setUseSignature(false);
    	mail.setToAddresses(new String[] { toAddress });
    	mail.setSubject('PDF Email Demo');
    	mail.setHtmlBody(body);
    	mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
		
		// Send the email
    	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
 
   		ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with PDF sent to '+toAddress));
 
    	return null;
	}

}